#ifndef ELDER_GUI_H_
#define ELDER_GUI_H_

/*
 * ----------------------
 * Global definitions
 * ----------------------
 */

// Screen dimensions 
#define SCREEN_WIDTH  480
#define SCREEN_HEIGHT 270

// Fonts path
#define FONT_PATH_MAX_LENGTH	32

#define FONT_GARA_PATH 		"./data/fonts/gara.ttf"
#define FONT_DIGITAL7_PATH 	"./data/fonts/digital-7.ttf"

// Images path
#define IMG_PATH "./data/images/"

// Colors definition
#define COLOR_BLACK		{0x00, 0x00, 0x00}
#define COLOR_WHITE		{0xFF, 0xFF, 0xFF}
#define COLOR_RED		{0xFF, 0x00, 0x00}
#define COLOR_GREEN		{0x00, 0xFF, 0x00}
#define COLOR_BLUE		{0x00, 0x00, 0xFF}

// Font maximum size
#define FONT_MAX_SIZE 24

// Maximum length of a text
#define TEXT_MAX_LENGTH 32

// Backlight
#define BACKLIGHT_BRIGHTNESS_SYS_FILE     "/sys/class/backlight/imx-bl/brightness"
#define BACKLIGHT_MAX_BRIGHTNESS_SYS_FILE "/sys/class/backlight/imx-bl/max_brightness"

// Console
#define CONSOLE_X_PLOT	202
#define CONSOLE_Y_PLOT	194

#define CONSOLE_BUFFER_SIZE	2048
#define CONSOLE_ROW_SIZE	48
#define CONSOLE_COL_SIZE	8

#define CONSOLE_FONT_PATH	"./data/fonts/gara.ttf"
#define CONSOLE_FONT_SIZE	10
#define	CONSOLE_FONT_COLOR	COLOR_WHITE


/*
 * ----------------------
 * Structures
 * ----------------------
 */
 
 // Font type
 typedef enum fontType {gara, digital7} fontType;
  
 // Console structure
 typedef struct guiConsole
 {
 	// Buffer
 	char buffer[CONSOLE_BUFFER_SIZE];
 	unsigned char startBuff;
 	unsigned char lastRow;
 	unsigned char lastCol;
 	
 	 	
 	// Font
 	TTF_Font* font;
 	SDL_Color fontColor;
 	 	
 } guiConsole;
 
 
 // Text element structure
 typedef struct textElement
 {
 	// String which format the output text
 	char format[TEXT_MAX_LENGTH];
  	
 	// Font of the string
 	const fontType fontName;
 	
 	// Size of the string
 	const unsigned char fontSize;
 	
 	// Color of the text
 	SDL_Color color;
 	
 	// Position
 	SDL_Rect position;
 	
 	// Update function
 	void (*updateFunc)(int index);
 	
 	// String contained by the text
 	char string[TEXT_MAX_LENGTH];
 	
 	// TTF_Font pointer
 	TTF_Font* font;
 	
 	// Text surface
 	SDL_Surface *sText;
 	
 	
 } textElement;
 
 
 /*
  * ----------------------
  * Texts
  * ----------------------
  */
  
  // Load fonts needed to draw texts
  int loadFonts(void);
  
  // Close all the fonts
  void closeFonts(void);
 
  // Draw all textual elements
  void drawTextElements(void);
  
  // Update texts functions
  void updateTime(int index);
  void updatePoints(int index); 
  void updateRun(int index);
  void updateBacklight(int index);
  
/* 
 * ----------------------
 * IHM
 * ----------------------
 */
 
 // Draw background
 void drawBackground(void);
 
 // Load images needed to draw background, bars and other stuff
 static int loadImages(void);
  
 // Initialize system modules
 static int initSystem(void);
 
 // Free SDL ressources and memory allocated space
 static void freeRessources(void);
 
 // Cleanup everything, and shutdown SDL
 void cleanup(void);
  
/*
 * ----------------------
 * IHM Utilities
 * ----------------------
 */
 
 // Draw an image at position (x,y)
 void drawImage(SDL_Surface *img, int x, int y);
 
/*
 * ----------------------
 * Event manager
 * ----------------------
 */
 
 // Manage event (mouse, keyboard etc.) for SDL
 void eventManager(void);
 
 /*
 * ----------------------
 * Context
 * ----------------------
 */
 
 void initContext(void);
 
 /*
 * ----------------------
 * Backlight control
 * ----------------------
 */
 
 // Backlight driver initialization
 int initBacklightControl(void);
 
 // Free backlight ressources
 void releaseBacklightControl(void);
 
 // Set brightness (0 to 100%)
 void setBrightness(unsigned char aValue);
 
 // Get brightness (0 to 100%)
 unsigned char getBrightness(void);
 
 /*
  * ----------------------
  * Gauges
  * ----------------------
  */
 
 SDL_Color getBattColor(int battValue);
 
 void updateBatteries(void);
 
 /*
  * ----------------------
  * Console
  * ----------------------
  */
  
  static int initConsole(void);
  
  void drawConsole(void);
  
  
  
#endif
